package com.h.chatroom.controller;

import com.h.chatroom.pojo.dataobject.Session;
import com.h.chatroom.service.SessionService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RequestMapping("/session")
@RestController
public class SessionController {
    @Resource(name = "sessionServiceImpl")
    private SessionService sessionService;

    // 获取登录 用户的所有 会话列表
    @RequestMapping("/getSessionList")
    @ResponseBody
    public List<Session> getSessionList(@NotNull(message = "用户ID不能为空") Integer userId) {
        log.info("获取登录用户 id: " + userId + "，的所有会话列表");
        return sessionService.getSessionList(userId);
    }

    @RequestMapping("/addSession")
    @ResponseBody
    public Map<String,Integer> addSession(@NotNull(message = "好友 ID 不能为空") Integer toUserId,@NotNull(message = "用户Id不能为空") Integer userId) {
        log.info("创建新的会话 创建者Id: " + userId + " 和这个好友 Id: " + toUserId + "进行创建");
        return sessionService.addSession(toUserId,userId);
    }
}
